# -*- coding: utf-8 -*-
"""
 Copyright 2005 Spike^ekipS <spikeekips@gmail.com>

	This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
"""

import datetime
from django.utils.safestring import mark_safe
from django.utils.dateformat import DateFormat
from django.template import Library
from django.utils.safestring import mark_for_escaping

register = Library()

@register.filter(name="terms")
def terms (doc, field_name) :
	try :
		return doc.get_field(field_name).get_terms()
	except AttributeError :
		return None

@register.filter(name="print_field_value")
def print_field_value (v) :
	if type(v) in (str, unicode, int, long, float, ) :
		return v
	elif type(v) in (list, tuple, ) :
		return mark_safe("""
<ul>
%s
</ul>
		""" % ("\n".join("<li>%s</li>" % i for i in v), ),
	)
	elif isinstance(v, datetime.datetime) :
		return DateFormat(v).format("r T")
	else :
		return v

@register.filter(name="check_field_highlighted")
def check_field_highlighted (doc, field_name) :
	return len(doc.get_highlighted(field_name)) > 0

@register.filter(name="highlight")
def hightlight (doc, field_name) :
	return mark_safe(doc.highlight(field_name))


"""
Description
-----------


ChangeLog
---------


Usage
-----


"""

__author__ =  "Spike^ekipS <spikeekips@gmail.com>"
__version__=  "0.1"
__nonsense__ = ""






